//-----------------------------------------------------------------------

// <copyright file="MemoFieldDefinition.cs" company="Jamie Knight">

// Copyright (c) Jamie Knight. All rights reserved.

// </copyright>

//-----------------------------------------------------------------------

using System;
using System.Windows.Controls;
using System.Windows.Data;

namespace DevKnightlie.WPF.AutoForm.FieldDefinitions
{
    public class MemoFieldDefinition : BaseFieldDefinition
    {
        #region Private Fields

        private int _maxLines = 5;

        #endregion

        #region Properties

        public int MaxLines
        {
            get
            {
                return _maxLines;
            }
            set
            {
                _maxLines = value;
            }
        }

        #endregion

        #region Methods

        public override void BuildInputControl()
        {
            ContentControl container = new ContentControl()
            {
                VerticalAlignment = System.Windows.VerticalAlignment.Stretch,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                Focusable = false
            };
            TextBox memoTextBox = new TextBox()
            {
                MaxLines = MaxLines,
                Height = 70, // TODO: Magic number should not be an arbitrary value
                AcceptsReturn = true,
                TextWrapping = System.Windows.TextWrapping.Wrap
            };
            Binding memoBinding = new Binding(PropertyName);
            BindingOperations.SetBinding(memoTextBox, TextBox.TextProperty, memoBinding);
            SetupEnabledBinding(memoTextBox);
            container.Content = memoTextBox;
            ContainerControl = container;
            InputControl = memoTextBox;
        }
        #endregion

    }
}
